package com.yu.mall.controller;

import com.yu.mall.dto.BaseDTO;
import com.yu.mall.dto.user.UserDTO;
import com.yu.mall.service.UserService;
import com.yu.mall.vo.ResultVO;
import com.yu.mall.vo.user.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.servlet.http.HttpServletRequest;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@RestController
@RequestMapping("user")
@Api(tags = "用户管理",value = "用户管理")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("get")
    @ApiOperation(value = "获取用户信息")
    public ResultVO<UserVO> get(BaseDTO baseDTO){
        return userService.get(baseDTO.getOpenid());
    }

    @PostMapping("bindUser")
    @ApiOperation(value = "绑定用户")
    public ResultVO<UserVO> bindUser(HttpServletRequest request,UserDTO userDTO) throws InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException {
        return userService.bindUser(request,userDTO);
    }

    @PostMapping("bindCard")
    @ApiOperation(value = "绑定卡劵")
    @ApiImplicitParam(name = "card",value="卡劵号",required=true)
    public ResultVO bindCard(BaseDTO baseDTO,String card){
        return userService.bindCard(baseDTO.getOpenid(),card);
    }
}
